package game.core
{
	import flash.utils.getDefinitionByName;
	
	import game.core.objects.Ball;
	import game.core.objects.PauseBall;
	import game.core.util.Cache;
	import game.core.util.MathUtil;
	import game.manager.XMLManager;
	
	public class BallFactory
	{
		public function BallFactory()
		{
		}
		
		public static function newInstance(className:String):Ball {
			var packageName:String = "game.core.objects.";
			className = packageName + className;
			var cls:Class = flash.utils.getDefinitionByName(className) as Class;
			var result:Ball = new cls() as Ball;
			return result;
		}
		
		public static function randomPauseBall(radius:Number,gName:String):Ball{
			var ball:Ball;
			var pauseProbability:Number = XMLManager.instance.getConfig("config",null,"pauseProbability");
			var hasPauseBall:Boolean = MathUtil.probability(pauseProbability);
			if(hasPauseBall){
				if(radius <= Ball.MIN_RADIUS){
					var cacheKey:String = gName + radius;
					if(!Cache.hasCache(cacheKey)){
						ball = new PauseBall();
						Cache.addCache(cacheKey,cacheKey);
					}
				}
			}
			if(!ball){
				ball = new Ball();
			}
			return ball;
		}
	}
}